package com.zhhs.jzcd.materialtype.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhhs.framework.aspectj.lang.annotation.Log;
import com.zhhs.framework.aspectj.lang.enums.BusinessType;
import com.zhhs.jzcd.materialtype.domain.BaseMaterialCategory;
import com.zhhs.jzcd.materialtype.service.IBaseMaterialCategoryService;
import com.zhhs.framework.web.controller.BaseController;
import com.zhhs.framework.web.domain.AjaxResult;
import com.zhhs.common.utils.poi.ExcelUtil;
import com.zhhs.framework.web.page.TableDataInfo;

/**
 * 素材类型Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/jzcd/materialtype")
public class BaseMaterialCategoryController extends BaseController
{
    @Autowired
    private IBaseMaterialCategoryService baseMaterialCategoryService;

    /**
     * 查询素材类型列表
     */
//    @PreAuthorize("@ss.hasPermi('jzcd:materialtype:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseMaterialCategory baseMaterialCategory)
    {
        startPage();
        List<BaseMaterialCategory> list = baseMaterialCategoryService.selectBaseMaterialCategoryList(baseMaterialCategory);
        return getDataTable(list);
    }

    /**
     * 导出素材类型列表
     */
    @PreAuthorize("@ss.hasPermi('jzcd:materialtype:export')")
    @Log(title = "素材类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseMaterialCategory baseMaterialCategory)
    {
        List<BaseMaterialCategory> list = baseMaterialCategoryService.selectBaseMaterialCategoryList(baseMaterialCategory);
        ExcelUtil<BaseMaterialCategory> util = new ExcelUtil<BaseMaterialCategory>(BaseMaterialCategory.class);
        util.exportExcel(response, list, "素材类型数据");
    }

    /**
     * 获取素材类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('jzcd:materialtype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseMaterialCategoryService.selectBaseMaterialCategoryById(id));
    }

    /**
     * 新增素材类型
     */
    @PreAuthorize("@ss.hasPermi('jzcd:materialtype:add')")
    @Log(title = "素材类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseMaterialCategory baseMaterialCategory)
    {
        return toAjax(baseMaterialCategoryService.insertBaseMaterialCategory(baseMaterialCategory));
    }

    /**
     * 修改素材类型
     */
    @PreAuthorize("@ss.hasPermi('jzcd:materialtype:edit')")
    @Log(title = "素材类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseMaterialCategory baseMaterialCategory)
    {
        return toAjax(baseMaterialCategoryService.updateBaseMaterialCategory(baseMaterialCategory));
    }

    /**
     * 删除素材类型
     */
    @PreAuthorize("@ss.hasPermi('jzcd:materialtype:remove')")
    @Log(title = "素材类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseMaterialCategoryService.deleteBaseMaterialCategoryByIds(ids));
    }



    /**
     * 素材树列表
     * @return
     */
    @GetMapping("/treeList")
    public AjaxResult treeList()
    {
        return AjaxResult.success(baseMaterialCategoryService.selectTreeList());
    }
}
